package cc.rengu.igas.momp.common.dao.impl;

import cc.rengu.igas.momp.common.dao.TMPlatTxnCodeMapMapper;
import cc.rengu.igas.momp.common.entity.TMPlatTxnCodeMap;
import cc.rengu.jradp.mods.dbs.Database;
import cc.rengu.oltp.service.common.constant.AppConfigConstant;
import cc.rengu.oltp.service.common.constant.AppParamConstant;
import cc.rengu.oltp.utility.util.DbsUtil;
import cc.rengu.oltp.utility.util.XmlConfigUtil;
import cc.rengu.oltp.utility.util.XmlTreeUtil;
import cc.rengu.utility.cache.UnifiedCache;
import cc.rengu.utility.log.RgLog;
import cc.rengu.utility.log.RgLogger;

/**
 * @author Jinan Liu
 * @date 2020/4/14 10:19
 * @description
 */

public class TMPlatTxnCodeMapMapperImpl implements TMPlatTxnCodeMapMapper {

    private RgLogger rglog = RgLog.getLogger(this.getClass().getName());
    String dbPoolName = XmlConfigUtil.getXmlConfigCacheKeyValue(AppParamConstant.DATABASE_CONF_NODE, AppConfigConstant.MOMP_POOL_NAME);

    /**
     * 使用联机交易支付交易码、业务分类和账户类型查询营销产品代码数据库操作接口实现
     *
     * @param tmPlatTxnCodeMap
     * @return cc.rengu.igas.momp.common.entity.TMPlatTxnCodeMap
     * @throws Exception 异常信息
     * @author Jinan Liu
     * @date 2020/4/14 10:24
     */
    @Override
    public TMPlatTxnCodeMap selectMompBizProductCodeByUsingTxnNum(TMPlatTxnCodeMap tmPlatTxnCodeMap) throws Exception {

        XmlTreeUtil xmlTreeUtil = new XmlTreeUtil();
        String corporation = xmlTreeUtil.getXmlTreeStringValue(AppParamConstant.CORPORATION);
        if (null != corporation && !corporation.isEmpty()) {
            String dbPoolCashNode = corporation.trim() + AppParamConstant.DATABASE_CONF_NODE;
            dbPoolName = XmlConfigUtil.getXmlConfigCacheKeyValue(dbPoolCashNode, AppConfigConstant.MOMP_POOL_NAME);
        }
        rglog.error("DBPoolName=[{}]", dbPoolName);

        DbsUtil dbsUtil = new DbsUtil(dbPoolName);
        String sqlStr = (String) UnifiedCache.get(AppParamConstant.SQL_MAPPER_CACHE, "selectMompProductInfoByUsingTxnNum");

        int iReturnCode = dbsUtil.dbsExecuteSql(sqlStr, tmPlatTxnCodeMap, tmPlatTxnCodeMap);
        if (Database.DBS_SUCCESS != iReturnCode) {
            rglog.error("根据查询条件法人机构号<{}>获取营销产品信息失败!<{}>", tmPlatTxnCodeMap.getInstId(), iReturnCode);
            return null;
        }

        return tmPlatTxnCodeMap;
    }
}
